package pl.put.to.regression;

import java.io.IOException;
import java.util.List;

import pl.put.to.regression.data.DataSet;
import pl.put.to.regression.linearprogramming.MinMaxProblem;
import pl.put.to.regression.verification.IErrorVeryficator;
import pl.put.to.regression.verification.LADErrorVefyficator;
import pl.put.to.regression.verification.LSErrorVefyficator;
import pl.put.to.regression.verification.MMErrorVefyficator;

public class MinMaxEntryPoint {
	public static void main(String[] args) {
		MinMaxProblem minMaxProblem = null;
		try {
			DataSet trainDataSet = new DataSet("data/DenBosch_train.data");

			long t0 = System.nanoTime();

			minMaxProblem = new MinMaxProblem(trainDataSet);
			minMaxProblem.solve();

			long t1 = System.nanoTime();

			System.out.println("Time: " + ((t1 - t0) / 1000000) + " ms");

			System.out.println(minMaxProblem.getObjective());
			System.out.println(minMaxProblem.getACoefficients());

			DataSet testDataSet = new DataSet("data/DenBosch_test.data");

			List<Double> coefficients = minMaxProblem.getACoefficients();

			IErrorVeryficator errorVeryficator = new LSErrorVefyficator();
			double lsErrorTrain = errorVeryficator.countError(trainDataSet, coefficients);
			double lsErrorTest = errorVeryficator.countError(testDataSet, coefficients);

			errorVeryficator = new LADErrorVefyficator();
			double ladErrorTrain = errorVeryficator.countError(trainDataSet, coefficients);
			double ladErrorTest = errorVeryficator.countError(testDataSet, coefficients);

			errorVeryficator = new MMErrorVefyficator();
			double mmErrorTrain = errorVeryficator.countError(trainDataSet, coefficients);
			double mmErrorTest = errorVeryficator.countError(testDataSet, coefficients);

			System.out.println("LS error on train set = " + lsErrorTrain);
			System.out.println("LS error on test set = " + lsErrorTest);
			System.out.println("LAD error on train set = " + ladErrorTrain);
			System.out.println("LAD error on test set = " + ladErrorTest);
			System.out.println("MM error on train set = " + mmErrorTrain);
			System.out.println("MM error on test set = " + mmErrorTest);

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (minMaxProblem != null) {
				minMaxProblem.disposeProblem();
			}
		}
	}
}
